package com.baidu.health.checkImages;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;

// 获取AccessToken 示例代码
public class getParameters {
    public static String getParameters() {
        String path = "https://aip.baidubce.com/oauth/2.0/token";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);


        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");

        // 设置query参数
        request.addQueryParameter("client_id", "so1v3GrGsuKDp3I2xGyvEMyj");
        request.addQueryParameter("client_secret", "v5LBzNModrwMLwM6U3Ubgxvm1HhD4XyW");
        request.addQueryParameter("grant_type", "client_credentials");

        // 设置jsonBody参数
        String jsonBody = "{}";
        request.setJsonBody(jsonBody);

        ApiExplorerClient client = new ApiExplorerClient();

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            System.out.println(response.getResult());
            return response.getResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}